<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 一定要给初始值
    const name = "mortal";
    console.log(name);

    // 常量的值不能修改
    // name = "mortal2";
    // 报错：
    // Uncaught TypeError: Assignment to constant variable.
    // console.log(name);

    // 常量一般使用大写

    // const属于块级作用域
    {
        const a = 10;
        console.log(a);
    }
    //  console.log(a);
    // 报错：
    // Uncaught ReferenceError: a is not defined


    // 对于数组和对象元素的修改不算是常量的修改,不会报错
    const obj = {
        name: "mortal",
        age: 18
    }
    obj.age = 20;
    console.log(obj);

</script>

</html>